#!/usr/bin/env python

#test_upload = 'http://127.0.0.1:8000/duetopia/register/dataset/import/rdf/'

test_upload = 'http://127.0.0.1:8000/duetopia/register/dataset/annotate/rdf/'

"""\
Usage: %prog [options] <uri>

Upload an RDF/XML file to a registry. Specify with -u or edit test_upload
"""

from optparse import OptionParser
from sys import exit
import urllib2

from duetopia.thredds import transform

if __name__ == '__main__':
    op = OptionParser(usage=__doc__)
    op.add_option("-u", "--upload",
            help="Upload (HTTP POST) serialized RDF/XML to URL",
            action="store",
            default=False
    )
    (options, args) = op.parse_args()
    if len(args) != 1:
        op.print_help()
        exit()
    if options.upload:
        upload = options.upload
    else:
        upload = test_upload

    file = args[0]
    try:
        data = open(file).read()
    except Exception, e:
        print e
        raise

    request = urllib2.Request(upload, data)
    fp = urllib2.urlopen(request)
    response = fp.read()
    fp.close()
    if response:
        print response
    
